home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / vector.lha / vector / hmatrix.c < prev    next >
C/C++ Source or Header  |  1991-11-23  |  673b  |  33 lines

  1. #include <hmatrix.h>
  2.  
  3. HomogenousMatrixImplement(float);
  4.  
  5. /* This is only done for HMat(float) right now because
  6.  *  of the global ::adjoint method (in C, yet).
  7.  */
  8.  
  9. #include "adjoint.h"
  10. /* Return the adjoint of a matrix, and the determinant
  11.  *  of the matrix in *det (if non-NULL).
  12.  * Negate the adjoint if the determinant of the matrix
  13.  *  is < 0, to fix problems with perspective matrices.
  14.  */
  15. HMat(float) adjoint(const HMat(float) &m, float *det) {
  16.     HMat(float) adj;
  17.     float v;
  18.  
  19.     v = ::adjoint(m, adj);
  20.  
  21.     if (v < 0) {
  22.     for (int i = X; i <= W; i++)
  23.         for (int j = X; j <= W; j++)
  24.         adj[i][j] = -adj[i][j];
  25.     }
  26.  
  27.     if (det)
  28.     *det = v;
  29.  
  30.     return adj;
  31. }
  32.  
  33.